package huawei;

import java.util.ArrayList;
import java.util.List;

public class Question2 {

    public boolean isGcd(int a, int b) {
        if (a < b) {
            int t = a;
            a = b;
            b = t;
        }

        while (b != 0) {
            int t = b;
            b = a % b;
            a = t;
        }

        return a == 1;
    }

    public List<List<Integer>> getGgs (int n, int m) {
        List<List<Integer>> result = new ArrayList<>();
        for (int i = n; i <= m; i++) {
            for (int j = i + 1; j <= m; j++) {
                double sqrt = Math.sqrt(i * i + j * j);
                if (sqrt == Math.floor(sqrt) && (int) sqrt <= m && isGcd(i, j) && isGcd(i, (int) sqrt) && isGcd(j, (int) sqrt)) {
                    ArrayList<Integer> tt = new ArrayList<>();
                    tt.add(i);
                    tt.add(j);
                    tt.add((int) sqrt);
                    result.add(tt);
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Question2 q = new Question2();
        System.out.println(q.getGgs(1, 20));
    }
}
